import * as util from "@/common/util";
import * as API from "@/api/axios";

export default {

    createModify: (params) => {
        const url = '/manage/whitelist-rules'
        const headers = {
            'lang-key': params.id ? 'branch_Edit' : 'branch_Create'
        }
        if (params.id) {
            return API.axiosPutAPI(url, params, headers)
        } else {
            return API.axiosPostAPI(url, params, headers)
        }
    },

    getPage: (params, page) => {
        const url = util.replacePageNumAndSize('/manage/whitelist-rules/{pageNum}/{pageSize}', page)
        return API.axiosGetAPI(url, params)
    },

    getDetail: (id) => {
        return API.axiosGetAPI(`/manage/whitelist-rules/${id}`)
    },

    // 获取白名单用户列表
    getPageUser: (params, page) => {
        const url = util.replacePageNumAndSize('/manage/whitelist-rules/users/{pageNum}/{pageSize}', page)
        return API.axiosGetAPI(url, params)
    },

    // 获取白名单用户详情
    getDetailUser: (id) => {
        return API.axiosGetAPI(`/manage/whitelist-rules/users/${id}`)
    },

    // 获取白名单规则选项
    getRuleOption: params => {
        return API.axiosGetAPI('/manage/whitelist-rules/option', params)
    },


    // 修改状态
    modifyState: (params) => {
        const headers = {
            'lang-key': params.state == 1 ? 'Station_Open' : 'Station_Close'
        }
        return API.axiosPutAPI('/manage/whitelist-rules/state', params, headers)
    },

    // 批量绑定用户
    bindUser: params => {
        const headers = {
            'lang-key': 'replacementBillingRules'
        }
        return API.axiosPostAPI('/manage/whitelist-rules/user/batch', params, headers)
    },

    // 批量解绑用户
    unbindUser: params => {
        const headers = {
            'lang-key': 'replacementBillingRules'
        }
        return API.axiosPutAPI('/manage/whitelist-rules/user/batch', params, headers)
    },

    // 编辑-用户白名单
    modifyUser: params => {
        const headers = {
            'lang-key': 'branch_Edit'
        }
        return API.axiosPutAPI('/manage/whitelist-rules/users', params, headers)
    },

    // 白名单规则-获取用户已绑定的规则
    userBoundRules: params => {
        return API.axiosGetAPI(`/manage/whitelist-rules/users/bound`, params)
    },

    // 白名单规则-删除
    deleteRules: id => {
        const headers = {
            'lang-key': 'delete'
        }
        return API.axiosDeleteAPI(`/manage/whitelist-rules/${id}`, '', headers)
    },

    // 获取用户列表
    getUsers: (params) => {
        return API.axiosGetAPI(`/manage/whitelist-rules/users`, params)
    },

    // 用户白名单-编辑状态
    editUsersState: params => {
        return API.axiosPutAPI(`/manage/whitelist-rules/users/state`, params)
    },


    // 用户-更新绑定规则
    userWhitelist: params => {
        return API.axiosPostAPI(`/manage/whitelist-rules/user/update-whitelist`, params)
    },


}